<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- <link rel="shortcut icon" href="img/logo.ico" /> -->
    <title>查看</title>
    <link href="plugin/date/date.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap3.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/nav.css" />
    <style media="screen">
        body{padding-bottom: 80px;}
    </style>
</head>

<body>
    <!--导航-->
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
                <a class="navbar-brand" href=""><img src="images/admin_logo.png" alt=""></a>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
                <ul class="nav navbar-nav" id="nav">
                    <li class="dropdown active">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-newspaper-o"></i>店铺<span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a class="navlist" target="_blank" href="user.html">店铺管理</a></li>
                            <li><a class="navlist" target="_blank" href="cooperation_audit.html">合作方申请记录</a></li>
                            <li><a class="navlist" target="_blank" href="member_rewards.html">会员业务奖励</a></li>
                            <li><a class="navlist" target="_blank" href="member_reward_rules.html">会员业务奖励规则</a></li>
                            <li><a class="navlist" target="_blank" href="agency_setting.html">合作方等级</a></li>
                            <li><a class="navlist" target="_blank" href="business_reward.html">合作方业务奖励</a></li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">欢迎您：<span id="uname"></span><span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <!-- <li><a href="change_pass.html">修改密码</a></li> -->
                            <li><a id="loginOut" href="#">退出登陆</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container-fluid">
        <div class="row bcert-box">
            <ol class="breadcrumb">
                <li><a href="javascript:;">主页</a></li>
                <li>店铺</li>
                <li class="active">店铺管理</li>
            </ol>
            <ul class="nav nav-tabs">
                <li role="presentation" class="active"><a href="shop_manage_editshop.html">店铺信息</a></li>
                <li role="presentation"><a href="shop_manage_edit_reginfo.html">注册信息</a></li>
            </ul><br>
            <form class="col-md-6">
                <div class="form-group">
                    <label for="exampleInputEmail1">店主账号：</label>
                    <p class="form-control-static" id="sellerName"></p>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1"><span class="text-danger">* </span>店铺名称：</label>
                    <input type="text" class="form-control" id="storeName" placeholder="">
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">开店时间：</label>
                    <p class="form-control-static" id="shopTime"></p>
                </div>
                <div class="form-group">
                    <label for="">所属分类：</label>
                    <select class="form-control" id="shopClass">

                    </select>
                </div>
                <div class="form-group">
                    <label for="">所属等级：</label>
                    <select class="form-control" id="shopLevel">

                    </select>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">有效期至：</label>
                    <input id="closeTime" class="form-control" placeholder="请选择有效期" name="closeTime" readonly title="错误" data-container="body" data-toggle="popover" data-placement="bottom" data-content="开始时间不能大于结束时间!">
                </div>

                <div class="form-group">
                    <label for="exampleInputPassword1">店铺保障服务开关：</label>
                    <div class="radio">
                        <label>
                            <input type="checkbox" name="storeSafeguard" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;保障服务
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="checkbox" name="storeDeposit" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;保证金&nbsp;
                            <input type="text" name="storeDepositAmount" value="">元
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <label for="exampleInputPassword1">保障内容开关：</label>
                    <div class="radio">
                        <label>
                            <input type="checkbox" name="storeTrue" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;正品保障
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="checkbox" name="storeEntity" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;实体店铺
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="checkbox" name="storeSeven" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;七天退换
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="checkbox" name="storeReturnPromise" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;退换承诺
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="checkbox" name="storeTrail" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;试验中心
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="checkbox" name="storeTwoHour" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;2H发货
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="checkbox" name="storePayOnDelivery" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;货到付款
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="checkbox" name="storeConsumerProtection" class="serviceSwitch" id="" value="0" aria-label="...">&nbsp;消费者保障
                        </label>
                        <label>
                    </div>
                </div>

                <div class="form-group">
                    <label for="exampleInputPassword1">状态：</label>
                    <div class="radio">
                        <label>
                            <input type="radio" name="storeState" id="stateOpen" value="1" aria-label="..." checked>&nbsp;开启
                        </label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="radio" name="storeState" id="stateClose" value="0" aria-label="...">&nbsp;关闭
                        </label>
                    </div>
                </div>

                <button type="button" class="btn btn-primary" id="btnUpStoreInfo">提交</button>
            </form>
            <!-- <div class="col-md-8">
                <table class="table table-bordered" id="integralList">

                </table>
            </div> -->
        </div>
        <!-- 分页 -->
        <!-- <nav aria-label="...">
            <div class="">
                <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
            </div>
            <ul id="example"></ul>
        </nav> -->
    </div>

    <!-- 编辑 -->
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="entinfo">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">编辑</h4>
                </div>
                <div class="modal-body" style="overflow:auto">
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">id</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" readonly="readonly" class="form-control" id="partner_id" placeholder="id"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">合作方名称</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" readonly="readonly" class="form-control" id="partner_name" placeholder="合作方等级名称"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">金牌小卫士每月新增数量（人）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="quantity" placeholder="金牌小卫士每月新增数量"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">营收（元）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="revenue" placeholder="营收"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">完成业绩分成比例（%）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="complete_reward" placeholder="完成业绩分成比例"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">未完成业绩分成比例（%）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="unfinished_bonus" placeholder="未完成业绩分成比例"></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="entBtn">确认提交</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>
</body>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="plugin/layer/layer.js"></script>
<script type="text/javascript" src="js/cookie.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script src="./js/ajax.js" charset="utf-8"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-paginator.js"></script>
<script type="text/javascript" src="plugin/date/date.js"></script>
<script type="text/javascript" src="plugin/date/date.zh-CN.js"></script>
<script src="./js/jquery.cookie.js" charset="utf-8"></script>
<!-- <script src="./plugin/bootstrap-switch-master/dist/js/bootstrap-switch.min.js" charset="utf-8"></script> -->
<script>
var scId,sgId,detailIdVal;
    function UrlSearch() {
        var name, value;
        var str = location.href; //取得整个地址栏;
        var num = str.indexOf("?")
        str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]

        var arr = str.split("&"); //各个参数放到数组里
        for (var i = 0; i < arr.length; i++) {
            num = arr[i].indexOf("=");
            if (num > 0) {
                name = arr[i].substring(0, num);
                value = arr[i].substr(num + 1);
                this[name] = value;
            }
        }
    }
    var Request = new UrlSearch(); //实例化
    var storeId = Request.id;
    $.cookie('cokstoreId',storeId,{ expires: 7});
    var cokstoreId = $.cookie('cokstoreId');
    // var serverURL = 'http://ww.wuyoutianxia.com/wy3pt';
    $("document").ready(function() {
        tableList();
        storeGradeList();
        storeClassList();
    });


    $("#closeTime").datetimepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        todayBtn: true,
        todayHighlight: true,
        showMeridian: true,
        pickerPosition: "top-left",
        language: 'zh-CN', //中文，需要引用zh-CN.js包
        startView: 2, //月视图
        minView: 2, //日期时间选择器所能够提供的最精确的时间选择视图

    })
    //分页

    $('#entinfo').on('hidden.bs.modal', function(e) {
        $('.modal-body input').val(null);
    })

    //获取店铺等级
    var storeGradeUrl = serverURL + '/platform/queryStoreGrade';

    function storeGradeList() {
        // data = {
        //
        // }
        //data.page = 1
        ajax(
            storeGradeUrl,
            data,
            InitstoreGradeList,
            'post',
            'json'
        )
    }

    function InitstoreGradeList(lvlist) {
        var lvlist = lvlist.data.list;
        for (i in lvlist) {
            $('#shopLevel').append('<option value="' + lvlist[i].sgId + '">' + lvlist[i].sgName + '</option>')
        }
        $('#shopLevel option[value="'+sgId+'"]').attr('selected',true)
    }

    //获取店铺分类
    var storeClassUrl = serverURL + '/platform/queryStoreClass';

    function storeClassList() {
        // data = {
        //
        // }
        //data.page = 1
        ajax(
            storeClassUrl,
            data,
            InitstoreClassList,
            'post',
            'json'
        )
    }

    function InitstoreClassList(clslist) {
        var clslist = clslist.data.list;
        for (i in clslist) {
            $('#shopClass').append('<option value="' + clslist[i].scId + '">' + clslist[i].scName + '</option>')
        }
        $('#shopClass option[value="'+scId+'"]').attr('selected',true)
    }


    var pageUrls = serverURL + '/platform/queryStoreById';

    function tableList() {
        data = {
            'storeId': cokstoreId,
            'edit': 'edit',
            'page': page,
            'pageSize': pagesize
        }
        data.page = 1
        ajax(
            pageUrls,
            data,
            OpendList,
            'post',
            'json'
        )
    }

    //数据渲染
    function OpendList(integralList) {
        var data = integralList.data;
        $('#sellerName').text(data.sellerName);
        // $('#sellerName').contains(data.sellerName)
        $('#storeName').val(data.storeName);
        $('#shopTime').text(data.checkTime);
        $('#closeTime').val(data.closeTime);
        $('input[name="storeDepositAmount"]').val(data.storeDepositAmount),
        detailIdVal = data.detailId;
        //店铺开启状态
        if (data.storeState == '0') {
            $('#stateClose').attr('checked', true)
        }
        if (data.storeState == '1') {
            $('#stateOpen').attr('checked', true)
        }

        //消费者保障
        if(data.storeConsumerProtection == '1'){
            $('input[name="storeConsumerProtection"]').attr('checked', true);
            $('input[name="storeConsumerProtection"]').val('1')
        }else{
            $('input[name="storeConsumerProtection"]').attr('checked', false);
            $('input[name="storeConsumerProtection"]').val('0')
        };

        //保证金显示开关
        if(data.storeDeposit == '1'){
            $('input[name="storeDeposit"]').attr('checked', true);
            $('input[name="storeDeposit"]').val('1')
        }else{
            $('input[name="storeDeposit"]').attr('checked', false);
            $('input[name="storeDeposit"]').val('0')
        };

        //实体验证
        if(data.storeEntity == '1'){
            $('input[name="storeEntity"]').attr('checked', true);
            $('input[name="storeEntity"]').val('1')
        }else{
            $('input[name="storeEntity"]').attr('checked', false);
            $('input[name="storeEntity"]').val('0')
        };

        //货到付款
        if(data.storePayOnDelivery == '1'){
            $('input[name="storePayOnDelivery"]').attr('checked', true);
            $('input[name="storePayOnDelivery"]').val('1')
        }else{
            $('input[name="storePayOnDelivery"]').attr('checked', false);
            $('input[name="storePayOnDelivery"]').val('0')
        };

        //退货承诺
        if(data.storeReturnPromise == '1'){
            $('input[name="storeReturnPromise"]').attr('checked', true);
            $('input[name="storeReturnPromise"]').val('1')
        }else{
            $('input[name="storeReturnPromise"]').attr('checked', false);
            $('input[name="storeReturnPromise"]').val('0')
        };

        //保障服务
        if(data.storeSafeguard == '1'){
            $('input[name="storeSafeguard"]').attr('checked', true);
            $('input[name="storeSafeguard"]').val('1')
        }else{
            $('input[name="storeSafeguard"]').attr('checked', false);
            $('input[name="storeSafeguard"]').val('0')
        };

        //7天退换
        if(data.storeSeven == '1'){
            $('input[name="storeSeven"]').attr('checked', true);
            $('input[name="storeSeven"]').val('1')
        }else{
            $('input[name="storeSeven"]').attr('checked', false);
            $('input[name="storeSeven"]').val('0')
        };

        //试用中心
        if(data.storeTrail == '1'){
            $('input[name="storeTrail"]').attr('checked', true);
            $('input[name="storeTrail"]').val('1')
        }else{
            $('input[name="storeTrail"]').attr('checked', false);
            $('input[name="storeTrail"]').val('0')
        };

        //正品保障
        if(data.storeTrue == '1'){
            $('input[name="storeTrue"]').attr('checked', true);
            $('input[name="storeTrue"]').val('1')
        }else{
            $('input[name="storeTrue"]').attr('checked', false);
            $('input[name="storeTrue"]').val('0')
        };

        //两小时发货
        if(data.storeTwoHour == '1'){
            $('input[name="storeTwoHour"]').attr('checked', true);
            $('input[name="storeTwoHour"]').val('1')
        }else{
            $('input[name="storeTwoHour"]').attr('checked', false);
            $('input[name="storeTwoHour"]').val('0')
        };

        scId = data.scId;
        sgId = data.sgId;
    }
    //删除
    $(document).on('click', '.listDel', function() {
        var id = $(this).attr('data-id')
        layer.confirm('确定要删除这条信息吗？', {
            btn: ['确定', '取消'] //按钮
        }, function() {
            deleteList(id)
        }, function() {});
    })
    //详情
    $(document).on('click', '.listEnt', function() {
        var id = $(this).attr('data-id')
        $.ajax({
            url: serverURL + '/member/queryPartnerLevelByPrimaryKey',
            type: "post",
            dataType: "json",
            data: {
                'partner_id': id,
            },
            success: function(data) {
                console.log(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    $('#partner_id').val(data.data.partner_id)
                    $('#partner_name').val(data.data.partner_name)
                    $('#quantity').val(data.data.quantity)
                    $('#revenue').val(data.data.revenue)
                    $('#complete_reward').val(data.data.complete_reward)
                    $('#unfinished_bonus').val(data.data.unfinished_bonus)
                    integralListPaga();
                }
            }
        });
    })

    //修改
    $('#entBtn').click(function() {
        $.ajax({
            url: serverURL + '/member/savePartnerLevel',
            type: "post",
            dataType: "json",
            data: {
                'partner_id': $('#partner_id').val(),
                'partner_name': $('#partner_name').val(),
                'quantity': $('#quantity').val(),
                'revenue': $('#revenue').val(),
                'complete_reward': $('#complete_reward').val(),
                'unfinished_bonus': $('#unfinished_bonus').val()
            },
            success: function(data) {
                console.log(data.msg)
                layer.msg(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    $('#entinfo').modal('hide')
                    integralListPaga();
                }
            }
        });
    })

    //删除
    function deleteList(id) {
        $.ajax({
            url: serverURL + '/member/delPartnerLevel',
            type: "post",
            dataType: "json",
            data: {
                'ids': id,
            },
            success: function(data) {
                console.log(data.msg)
                layer.msg(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    integralListPaga();
                }
            }
        });
    }

    $('.serviceSwitch').change(function () {
        if($('.serviceSwitch:checked')){
            $(this).val('1')
        }else{
            $(this).val('0')
        }
    });

    $('#btnUpStoreInfo').click(function() {
        if ($('#storeName').val() == '') {
            layer.tips('请填写店铺名称', '#storeName', {
                tips: [1, '#FF5722'] //还可配置颜色
            });
            return
        }

        if ($('#closeTime').val() == '') {
            layer.tips('请填写有效期', '#closeTime', {
                tips: [1, '#FF5722'] //还可配置颜色
            });
            return
        }

        // if($('input[name="storeDeposit"]').val()=='1'){
        //     $('input[name="storeDepositAmount"]').val() == '';
        // }

        var t = $('#closeTime').val()
        var array =  t.split("-");
        var dt = new Date(array[0], array[1], array[2]);
console.log(detailIdVal);
        var data = {
            'storeId': cokstoreId,
            'detailId':detailIdVal,
            'storeName': $('#storeName').val(),
            'scId': $('#shopClass').val(),
            'sgId': $('#shopLevel').val(),
            'closeTime': dt,
            'storeState':$('input[name="storeState"]:checked').val(),
            'storeSafeguard':$('input[name="storeSafeguard"]').val(),
            'storeDeposit':$('input[name="storeDeposit"]').val(),
            'storeDepositAmount':$('input[name="storeDepositAmount"]').val(),
            'storeSeven':$('input[name="storeSeven"]').val(),
            'storeTrue':$('input[name="storeTrue"]').val(),
            'storeTwoHour':$('input[name="storeTwoHour"]').val(),
            'storeReturnPromise':$('input[name="storeReturnPromise"]').val(),
            'storeTrail':$('input[name="storeTrail"]').val(),
            'storeEntity':$('input[name="storeEntity"]').val(),
            'storeConsumerProtection':$('input[name="storeConsumerProtection"]').val(),
            'storePayOnDelivery':$('input[name="storePayOnDelivery"]').val()
        }
//console.log(typeof $('#closeTime').val());

        //console.log(dt);
        //console.log(cokstoreId);
        var pageUrls = serverURL + '/platform/updateStore';

        ajax(
            pageUrls,
            data,
            tableList,
            'post',
            'json'
        )
    })
</script>

</html>
